package com.example.demo.thread.线程的6个状态;

import java.util.concurrent.TimeUnit;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        Thread a = new Thread(new Runnable() {
            @Override
            public void run() {
                testMethod();
            }
        }, "a");
        Thread b = new Thread(new Runnable() {
            @Override
            public void run() {
                testMethod();
            }
        }, "b");

        a.start();
        a.join(3000);
        System.out.println(a.getName() + ":" + a.getState()); // 输出？
        //TimeUnit.MILLISECONDS.sleep(1000);
        b.start();

        //

        System.out.println(a.getName() + ":" + a.getState()); // 输出？
        System.out.println(b.getName() + ":" + b.getState()); // 输出？
    }


    private static synchronized void testMethod() {
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
